using System.Collections;
using Wilco.SyntaxHighlighting.Engine.Highlighter;

namespace Wilco.SyntaxHighlighting.Engine.Highlighter
{
    /// <summary>
    /// Represents a collection of highlighters.
    /// </summary>
    public class HighlighterCollection : CollectionBase
    {
        /// <summary>
        /// Initializes a new instance of a <see cref="HighlighterCollection"/> class.
        /// </summary>
        public HighlighterCollection()
        {
        }

        /// <summary>
        /// Gets the highlighter at the specified index.
        /// </summary>
        public HighlighterBase this[int index]
        {
            get
            {
                return (HighlighterBase)List[index];
            }
        }

        /// <summary>
        /// Gets the highlighter with the specified name.
        /// </summary>
        public HighlighterBase this[string name]
        {
            get
            {
                HighlighterBase highlighter;
                for (int i = 0; i < List.Count; i++)
                {
                    highlighter = (HighlighterBase)List[i];
                    if (highlighter.Name.ToLower() == name.ToLower())
                        return highlighter;
                }
                return null;
            }
        }

        /// <summary>
        /// Adds an highlighter.
        /// </summary>
        /// <param name="highlighter">The highlighter to add.</param>
        /// <returns>Index of the added highlighter.</returns>
        public int Add(HighlighterBase highlighter)
        {
            return List.Add(highlighter);
        }

        /// <summary>
        /// Removes an highlighter.
        /// </summary>
        /// <param name="highlighter">The highlighter to remove.</param>
        public void Remove(HighlighterBase highlighter)
        {
            List.Remove(highlighter);
        }
    }
}